export async function promiseObject(obj){
  const keys = Object.keys(obj);
  const promises = keys.map(k => obj[k]);
  const values = await Promise.all(promises);
  const out = {} ;
  keys.forEach((k, i) => {
    out[k] = values[i];
  });
  return out;
}
// 包装成数组
export function forceArray(t) {
  return Array.isArray(t) ? t : [t];
}

/**
 * 将字符串数组转换为具有"true"值的对象，例如用于快速查找。
 */
export function makeLookup(array){
  const o = {};
  array.forEach(key => {
    o[key] = true;
  });
  return o;
}

// 将字符串的点位解析成二维数组
export function parseShape(shape) {
  return shape.split(' ').map(coord => coord.split(',').map(Number));
}

export function stringHash(str) {
  var hash = 5381,
      i    = str.length;

  while(i) {
    hash = (hash * 33) ^ str.charCodeAt(--i);
  }

  /* JavaScript does bitwise operations (like XOR, above) on 32-bit signed
   * integers. Since we want the results to be always positive, convert the
   * signed int to an unsigned by doing an unsigned bitshift. */
  return hash >>> 0;
}